﻿@model IEnumerable<WebApp.Models.S_role>

<div id="breadcrumb">
    <a href="#"><i class="fa fa-bookmark"></i> 系统管理</a>
    <a href="#" class="current">用户日志</a>
</div>
<div class="row">
    <div class="col-xs-12">
        <div class="form-horizontal">
            <ul class="wysihtml5-toolbar">
                <li>
                    <button id="btndel" class="btn btn-small btn-danger">删除</button>
                </li>
                <li class="toolbar-right">
                    <div class="col-xs-12 nopadding" style="width:300px;">
                        <div class="input-group nopadding">
                            <input class="form-control" type="text" id="searchkey" data-fieldname="searchkey" placeholder="输入用户名">
                            <span class="input-group-btn">
                                <button id="btnquery" class="btn btn-primary" type="button"><i class="fa fa-search"></i> 查询</button>
                            </span>
                        </div>
                    </div>
                </li>
                <li class="toolbar-right">
                    <table border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td>@Html.DatePicker("ToSearcheDate", null, "yyyy-MM-dd", new { @class = "", @readonly = true, style = "width:80px;" })</td>
                            <td>&nbsp;~&nbsp;</td>
                            <td>@Html.DatePicker("FromSearcheDate", null, "yyyy-MM-dd", new { @class = "", @readonly = true, style = "width:80px;" })</td>
                        </tr>
                    </table>
                </li>
                <li class="toolbar-right">
                    @Html.DropDownList("Opartype", ViewBag.Opartypelist as SelectList, "全部分类", new { @class = "form-control pull-right", @style = "width:auto;" })
                </li>
            </ul>
        </div>

    </div>
</div>
<div class="row">
    <div class="col-xs-12" data-autosize="true">
        <table id="datagrid" fit="true"></table>
    </div>
</div>

@section scripts{
    <script type="text/javascript">
        var canEdit = @(ViewBag.CanEdit ? "true" : "false");

        //编辑对话框
        var dlg = new MyAppDialog(900, 600);
        //关闭对话框
        function closeDialog(reload) {
            dlg.close();

            if (reload)
                $("#datagrid").datagrid("reload");
        }

        $(document).ready(function(){
            if (!canEdit) {
                $("#btndel").hide();
            }

            //删除
            $("btndel").click(function(evt){
                evt.preventDefault();
                del();
            });
            //查询
            $("#btnquery").click(function (evt) {
                evt.preventDefault();
                var params = $("#datagrid").datagrid('options').queryParams;
                params.s = $("#searchkey").val();
                params.fromsearchdate=$("#FromSearcheDate").val();
                params.tosearchdate=$("#ToSearcheDate").val();
                params.type =$("#Opartype").val();
                $("#datagrid").datagrid("load");
            });
            $("#Opartype").change(function () {
                var params = $("#datagrid").datagrid('options').queryParams;
                params.s = $("#searchkey").val();
                params.fromsearchdate=$("#FromSearcheDate").val();
                params.tosearchdate=$("#ToSearcheDate").val();
                params.type = $("#Opartype").val();
                $("#datagrid").datagrid("load");
            });
            //$("#SearcheDate").change(function(){
            //    var params = $("#datagrid").datagrid('options').queryParams;
            //    params.s = $("#searchkey").val();
            //    params.searchdate=$("#SearcheDate").val();
            //    params.type = $("#Opartype").val();
            //    $("#datagrid").datagrid("load");
            //});
            $("#searchkey").keydown(function (event) {
                if (event.keyCode == $.ui.keyCode.ENTER) {
                    event.preventDefault();
                    $("#btnquery").click();
                    return false;
                }
            });
            LoadDatagrid();
        });

        //列定义
        var cols = [[
                        { field: "Id", title: 'Id', width: 10, hidden: true },
                        { field: "ck", title: '', width: 20, checkbox: true },
                        {field:"Oprttype",title:'日志类型',sortable:true,width:100, align: 'center'},
                        { field: "Username", title: '用户名', sortable: true, width: 100, align: 'center'},
                        //{ field: "Custname", title: '客户名称', sortable: true, width: 100, align: 'center' },
                        { field: "Oprttime", title: '时间', sortable: true, width: 80, align: 'center' },
                        { field: "Ip", title: 'IP', sortable: true, width: 80, align: 'center' }

        ]];

        //加载列表数据
        function LoadDatagrid() {
            var $dg = $("#datagrid");
            $dg.datagrid({
                title: '用户日志',
                url: baseurl + 'Manage/Userlog/UserlogListJson',
                fit: true,
                fitColumns: true,
                striped: true,
                nowrap: true,
                idField: 'Id',
                pagination: true,
                pageNumber: 1,
                pageSize: 20,
                pageList: [10, 20, 30, 45, 60, 75],
                rownumbers: true,
                singleSelect: false,
                queryParams: {
                    s: "",
                    fromsearchdate:$("#FromSearcheDate").val(),
                    tosearchdate:$("#ToSearcheDate").val(),
                    type: $("#Opartype").val()
                },
                sortName: 'Id',
                sortOrder: 'asc',
                columns: cols,
                onLoadSuccess: function () {
                    //多选时，加载完成后清除所有选中项（不然可能会有残留选中项）
                    $dg.datagrid("clearSelections");
                },
                //onSelect: function (rowIndex, row) {
                //    var selectedRows = $dg.datagrid("getSelections");
                //    if (selectedRows.length == 0) {
                //        $("#btndel").attr("disabled", true);
                //    } else {
                //        $("#btndel").attr("disabled", false);
                //    }
                //},
                //onUnselect: function (rowIndex, row) {
                //    var selectedRows = $dg.datagrid("getSelections");
                //    if (selectedRows.length == 0) {
                //        $("#btndel").attr("disabled", true);
                //    } else {
                //        $("#btndel").attr("disabled", false);
                //    }
                //}
            });
            //PaginationInit();
        }

        //删除
        function Del()
        {
            var row = $("#datagrid").datagrid('getSelections');
            if (row.length == 0) {
                $.messager.alert(csms_lang.message_info_title,csms_lang.message_delete_choosedelete);
                return;
            }
            $.messager.confirm(csms_lang.message_confirm, csms_lang.message_delete_confrim, function (r) {
                if (r) {
                    var ids = "";
                    for (var i = 0; i < row.length; i++) {
                        ids += row[i].Id + ",";
                    }

                    $.ajax({
                        type: "post",
                        url: baseurl + "Manage/Userlog/Delete",
                        data: { ids: ids },
                        success: function (e) {
                            if (e.Ret == "0") {
                                $("#datagrid").datagrid("reload");
                            } else {
                                $.messager.alert(csms_lang.message_error, e.Msg);
                            }
                        }
                    });
                }
            });
        }

    </script>
}
